package com.feihong.yw189.activity.yonghuzhongxin;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.feihong.yw189.R;
import com.feihong.yw189.activity.yonghuzhongxin.zhuanzhang.AddMoneyDetailActivity;
import com.feihong.yw189.activity.yonghuzhongxin.zhuanzhang.RollOutActivity;
import com.feihong.yw189.model.User.money.AccountDetailModel;
import com.feihong.yw189.model.User.money.AddingMoneyDetailModel;
import com.feihong.yw189.model.User.money.RollOutDetailModel;

/**
 * Created by PVer on 2017/12/27.
 */

public class AddmoeyDialog extends Dialog {

    TextView mySettingDialogTitle;
    TextView mySettingDialogOrder;
    TextView myAddingMoneyDialogOrder;
    TextView mySettingDialogTime;
    TextView myAddingMoneyDialogTime;
    TextView mySettingDialogStatus;
    TextView myAddingMoneyDialogStatus;
    TextView mySettingDialogType;
    TextView myAddingMoneyDialogType;
    TextView mySettingDialogMoney;
    TextView myAddingMoneyDialogMoney;
    TextView mySettingDialogNote;
    TextView myAddingMoneyDialogNote;

    private AddingMoneyDetailModel.DataBean.ListBean item;
    private AccountDetailModel.DataBean.ListBean itemAccount;
    private RollOutDetailModel.DataBean.ListBean itemOut;

    private Activity mContext;
    private int type = 0;

    public AddmoeyDialog(Context context, AddingMoneyDetailModel.DataBean.ListBean item) {
        super(context, R.style.MyDefindDialog);
        mContext = (AddMoneyDetailActivity) context;

        this.item = item;

        initView();
    }

    public AddmoeyDialog(Context context, AccountDetailModel.DataBean.ListBean item) {
        super(context, R.style.MyDefindDialog);
        mContext = (AddMoneyDetailActivity) context;

        type = 1;

        this.itemAccount = item;

        initView();
    }

    public AddmoeyDialog(Context context, RollOutDetailModel.DataBean.ListBean item) {
        super(context, R.style.MyDefindDialog);
        mContext = (RollOutActivity) context;

        type = 2;

        this.itemOut = item;

        initView();
    }

    public void initView() {
        setContentView(R.layout.my_adding_money_dialog);

        String[] listAddName = null;
        String orderItem = "", timeItem = "", statusItem = "", typeItem = "", moneyItem = "", noteItem = "", relItem = "", plantItem = "";

        if(type == 0) {
            listAddName = new String[]{"加款详情", "加款单号:", "加款时间:", "加款状态:", "加款方式:", "加款金额:", "加款备注:"};
            orderItem = item.getOrder_sn();
            timeItem = item.getAdd_time();
            statusItem = item.getStatus();
            typeItem = item.getType();
            moneyItem = item.getMoney();
            noteItem = item.getNote();

        }else if(type == 2){
                listAddName = new String[]{"转账详情", "转账流水号:", "收款账号:", "收款人:", "转账时间:", "转账状态:", "备注信息:", "转账金额:", "预计到账:",};
                orderItem = itemOut.getTrade_id();
                timeItem = itemOut.getOpen_bank()+"("+itemOut.getBank_num()+")";
                statusItem = itemOut.getOpen_name();
                typeItem = itemOut.getLast_time();
                moneyItem = itemOut.getIs_ok_name();
                //转账金额
                relItem = itemOut.getMoney();
                //预计到账
                plantItem = itemOut.getIs_ok();
                noteItem = itemOut.getNote();

        }else{
            listAddName = new String[]{"收支详情", "流水单号:", "交易时间:", "交易进出:", "交易类型:", "交易金额:", "交易说明:"};
            orderItem = itemAccount.getOrder_sn();
            timeItem = itemAccount.getTime();
            statusItem = itemAccount.getType();
            typeItem = itemAccount.getLog_type();
            moneyItem = itemAccount.getMoney();
            noteItem = itemAccount.getNote();
        }

        mySettingDialogTitle = (TextView) findViewById(R.id.my_setting_dialog_title);
        mySettingDialogTitle.setText(listAddName[0]);

        mySettingDialogOrder = (TextView) findViewById(R.id.my_setting_dialog_order);
        mySettingDialogOrder.setText(listAddName[1]);

        myAddingMoneyDialogOrder = (TextView) findViewById(R.id.my_adding_money_dialog_order);
        myAddingMoneyDialogOrder.setText(orderItem);

        mySettingDialogTime = (TextView) findViewById(R.id.my_setting_dialog_time);
        mySettingDialogTime.setText(listAddName[2]);

        myAddingMoneyDialogTime = (TextView) findViewById(R.id.my_adding_money_dialog_time);
        myAddingMoneyDialogTime.setText(timeItem);

        mySettingDialogStatus = (TextView) findViewById(R.id.my_setting_dialog_status);
        mySettingDialogStatus.setText(listAddName[3]);

        myAddingMoneyDialogStatus = (TextView) findViewById(R.id.my_adding_money_dialog_status);
        myAddingMoneyDialogStatus.setText(statusItem);

        mySettingDialogType = (TextView) findViewById(R.id.my_setting_dialog_type);
        mySettingDialogType.setText(listAddName[4]);

        myAddingMoneyDialogType = (TextView) findViewById(R.id.my_adding_money_dialog_type);
        myAddingMoneyDialogType.setText(typeItem);

        mySettingDialogMoney = (TextView) findViewById(R.id.my_setting_dialog_money);
        mySettingDialogMoney.setText(listAddName[5]);

        myAddingMoneyDialogMoney = (TextView) findViewById(R.id.my_adding_money_dialog_money);
        myAddingMoneyDialogMoney.setText(moneyItem);

        mySettingDialogNote = (TextView) findViewById(R.id.my_setting_dialog_note);
        mySettingDialogNote.setText(listAddName[6]);

        myAddingMoneyDialogNote = (TextView) findViewById(R.id.my_adding_money_dialog_note);
        myAddingMoneyDialogNote.setText(noteItem);


        if(type == 2){
            (findViewById(R.id.roll_out)).setVisibility(View.VISIBLE);

            (findViewById(R.id.roll_plan)).setVisibility(View.VISIBLE);

            TextView rollOutName = (TextView) findViewById(R.id.roll_out_rell_name);
            rollOutName.setText(listAddName[7]);
            TextView rollOutValue = (TextView) findViewById(R.id.roll_out_rell_vale);
            rollOutValue.setText(relItem);


            TextView rollPlanName = (TextView) findViewById(R.id.roll_plan_name);
            rollPlanName.setText(listAddName[8]);
            TextView rollPlanValue = (TextView) findViewById(R.id.roll_plan_vale);
            rollPlanValue.setText(plantItem);
        }
    }

    public void showDialog() {
        show();
        WindowManager windowManager = mContext.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); //设置宽度
        getWindow().setAttributes(lp);
    }

}
